import React, { useReducer } from 'react'
import { Button } from 'antd';
// 处理函数
const reducer = (prevState, action) => {
    let newState = {...prevState}
    switch (action.type) {
        case "add":
            newState.count++
            return newState;
        case "minus":
            newState.count--
            return newState;
        default:
            return prevState;
    }
}
const initialState = {
    count: 0
}
export default function App() {
    const [state, dispatch] = useReducer(reducer, initialState)
    return (
        <div>
            <Button type="primary" onClick={() => {
                dispatch({
                    type: "add"
                })
            }}>+</Button>
            <div>
                {state.count}
            </div>
            <Button type="primary" onClick={() => {
                dispatch({
                    type: "minus"
                })
            }}>-</Button>
        </div>
    )
}
